var app = new Vue({
    el: '#tab',
    data: {
        result: []
    }
})

var getUserPageList = function (curr) {
    var paper = {
        "paper_name":$("#paper_name").val(),
        teacher:{
            "teacher_name":$("#teacher_name").val(),
        }
    }
    $.ajax({
        type: "GET",
        dataType: "json",
        url: "/paper/getListPapers.do",
        data: {
            pageNum: curr || 1,
            pageSize: 10,
            "paper_name": $("#paper_name").val(),
            "teacher.teacher_name": $("#teacher_name").val(),
        },
        success: function (data) {
            app.result = data.page;
            laypage({
                skin: '#96F1F7',
                cont: 'pagenav', //容器。值支持id名、原生dom对象，jquery对象,
                pages: data.totalPages, //总页数
                first: "第一页",
                last: "最后一页",
                curr: curr || 1, //当前页
                jump: function (obj, first) { //触发分页后的回调
                    if (!first) { //点击跳页触发函数自身，并传递当前页：obj.curr
                        getUserPageList(obj.curr);
                    }
                }
            });
        }
    });
}
getUserPageList();
$("#findUser").on("click", function () {
    getUserPageList();
});
$("#paper_name").change(
    function () {
        getUserPageList();
    }
);
$("#teacher_name").change(
    function () {
        getUserPageList();
    }
);
$("#addUser").on("click",function () {
    layer.open({
        type:2,
        title:'添加新试卷',
        fix:false,
        maxmin:true,
        shadeClose:true,
        area:['900px','600px'],
        content:'/paper/showAddPaPer.do',

    });
});
var upLine = function (paper_id,online_state) {
    var state = 0;
    if (online_state == 1 ){
        state = 0;
    }else{
        state = 1;
    }
    layer.confirm('确定要更改该试卷的状态吗？',{
            btn:['是','否']
        },function () {
            $.ajax({
                type:"GET",
                dataType:"json",
                url:"/paper/editOnline.do",
                data:{
                    "paper_id":paper_id,
                    "online_state":state
                },
                success:function (data) {
                    if (data!=null){
                        getUserPageList();
                        layer.msg("状态修改成功",{icon: 1});

                    }else{
                        layer.msg("修改失败，请稍后重试",{icon:5})
                    }
                }
            });
        }
    )
}

var delEvent = function (paper_id) {
    layer.confirm('确定删除？', {
            btn: ['是', '否']
        }, function () {    //如果点击了第一个按钮 ——是
            $.ajax({
                type: "GET",
                dataType: "json",
                url: "/paper/delePaper.do",
                data: {
                    "paper_id": paper_id
                },
                success: function (data) {
                    getUserPageList();
                    if (data!=null){
                        layer.msg("已经删除了id为" + paper_id + "的记录", {icon: 1});
                    }else {
                        layer.msg("删除失败", {icon: 5});
                    }

                }
            });
        }
    );
}
var editEvent = function (paper_id) {
    layer.open({
        type:2,
        title:"修改试卷基本信息",
        fix:false,
        maxmin:true,
        shadeClose:true,
        area:['900px','600px'],
        content:'/paper/findpa.do?paper_id=' + paper_id,
    })

}

var showPaper = function (paper_id) {
    location.href="/paper/showPeper.do?paper_id="+paper_id;
}
function module(a){
    if (a == 1){
        $(".myExam").css("display","block");
        $(".sim").css("display","none");
    }
    if (a == 2){
        $(".myExam").css("display","none");
        $(".sim").css("display","block");
    }
}
$(".left>ul>li").click(function () {
    $(this).css({"background-color":"#30A4FF","color":"white"});
    $(".left>ul>li").not(this).css({"background-color":"white","color":"black"});
})